package com.eastcom.bm.dao.impl;

import java.util.ArrayList;
import java.util.List;

import com.eastcom.bm.atom.Atom_ActionRule;
import com.eastcom.bm.dao.IActionRuleDao;
import com.eastcom.common.db.JDBCTemplate;
import com.eastcom.common.db.ResultData;

public class ActionRuleDao implements IActionRuleDao {

	public Atom_ActionRule getActionRuleByDataSetId(String datasetId)throws Exception {
		try{
			Atom_ActionRule actionRule=null;
			
			ResultData rd=JDBCTemplate.executeSQLQuery("select * from qa_actionrule where dataset_id='"+datasetId+"'", JDBCTemplate.PROPAGATION_NEVER, false, false);
			if(rd.next()){
				actionRule=new Atom_ActionRule();
				
				actionRule.setUuid(rd.getString("UUID"));
				actionRule.setActionType(rd.getString("ACTION_TYPE"));
				actionRule.setAlarmLevel(rd.getString("ALARM_LEVEL"));
				actionRule.setDatasetId(rd.getString("DATASET_ID"));
				actionRule.setObjectUUID(rd.getString("OBJECT_UUID"));
			}

			return actionRule;
		}
		catch(Exception e){
			throw e;
		}
	}

	public List<Atom_ActionRule> getAllActionRule() throws Exception {
		try{
			List<Atom_ActionRule> results=new ArrayList<Atom_ActionRule>();
			
			ResultData rd=JDBCTemplate.executeSQLQuery("select * from qa_actionrule", JDBCTemplate.PROPAGATION_NEVER, false, false);
			while(rd.next()){
				Atom_ActionRule actionRule=new Atom_ActionRule();
				
				actionRule.setUuid(rd.getString("UUID"));
				actionRule.setActionType(rd.getString("ACTION_TYPE"));
				actionRule.setAlarmLevel(rd.getString("ALARM_LEVEL"));
				actionRule.setDatasetId(rd.getString("DATASET_ID"));
				actionRule.setObjectUUID(rd.getString("OBJECT_UUID"));
				results.add(actionRule);
			}

			return results;
		}
		catch(Exception e){
			throw e;
		}
	}

}
